package com.lcp.se.controller;

import com.lcp.se.entity.result.Result;
import com.lcp.se.service.VideoCallService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 视频通话消息处理
 *
 * @author lcp
 * @date 2020/8/12 21:37
 */
@RestController
@RequestMapping(value = "/user/videocall")
public class VideoCallController {

    @Resource
    private VideoCallService videoCallService;

    /**
     * 求助端发起一个音视频通话请求，返回相关数据
     *
     * @param openId 用户openId
     * @return id(本次通话的id), userSig，roomID
     */
    @PostMapping("/create")
    public Result<Map<String, Object>> createCall(@RequestHeader(value = "openId") String openId) {
        return videoCallService.createCall(openId);
    }

    /**
     * 服务端接受一个音视频通话请求，返回相关数据
     *
     * @param openId 用户openId
     * @return id(本次通话的id)，userSig
     */
    @PostMapping("/handle")
    public Result<Map<String, Object>> handleCall(@RequestHeader(value = "openId") String openId,
                                                  @RequestParam("callId") String callId) {
        return videoCallService.handleCall(openId,callId);
    }

    /**
     * 结束通话
     *
     * @param callId 通话的id
     * @return 处理结果
     */
    @PostMapping("/end")
    public Result<Map<String, Object>> endCall(@RequestParam("callId") String callId) {
        return videoCallService.endCall(callId);
    }
}
